import { log } from "console";

interface Person {
  /**
   * 名称
   */
  name:string  
  /**
   * 性别
   */
  sex:string  
   /**
   * 年龄
   */
  age:number  
}



const obj12:Person = {
  name:'zhichao',
  age:23,
  sex:'nan'
}




export interface InterfaceUserData {

  // 可选： dept_id, gender?, id, is_deleted
  /**
   * 头像
   */
  avatar: string;
  create_by: number;
  dept_id?: number | undefined;
  /**
   * 邮箱
   */
  email: string;
  /**
   * 性别
   */
  gender?: number | undefined;
  id?: number | undefined;
  is_deleted?: number | undefined;
  /**
   * 手机号
   */
  mobile?: string | undefined;
  /**
   * 昵称
   */
  nickname?: string | undefined;
  /**
   * 密码
   */
  password?: string | undefined;
  /**
   * 状态
   */
  status?: number | undefined;
  update_by?: number | undefined;
  /**
   * 用户名
   */
  readonly  username: string;

  // 额外的属性检查//允许添加新的任意属性
  [property: string]: string | number | boolean  | undefined;
}


let user1:InterfaceUserData = {
   username:'zhichao',
  avatar:'./touxiang.png',
  create_by:2342342,
  email:'234@qq.com',
  aihao:'jk',
  gongji:100,
  isNvpengyou:false
}




// user1.username = 'zhichao2' // 无法为“username”赋值，因为它是只读属性。ts(2540)


// 使用interface定义函数类型

interface IFun1 {
  (a:string,b:number):void
}

let fun111:IFun1 = function() {
  return '22'
}


console.log(fun111('234',2323));



function fun222():void {
  // return 222 // 不能将类型“number”分配给类型“void”。ts(2322)
}

console.log(fun222());



// 重名合并

interface IA{
  name:string
}
interface IA{
  sex:string
}
interface IA{
  age:string
}
interface IA{
  love:string
}


let obj10:IA = {
  age:'234',
  name:'chao',
  sex:'nan',
  love:'nv'
}



//继承
interface IA1{
  name:string
}

interface IB1 extends IA1{
  name:string
  age:number
}

let obj:IB1 = {
  age:18,
  name:"string"
}





interface IDataBaseForm {
  /**
   * 头像
   */
  avatar: string;
  create_by: number;
  dept_id: number;
  /**
   * 邮箱
   */
  email: string;
  /**
   * 性别
   */
  gender: number;
  id: number;
  is_deleted: number;
}

export interface IData extends IDataBaseForm,IB1{
  
  /**
   * 手机号
   */
  mobile: string;
  /**
   * 昵称
   */
  nickname: string;
  /**
   * 密码
   */
  password: string;
  /**
   * 状态
   */
  status: number;
  update_by: number;
  /**
   * 用户名
   */
  username: string;
  [property: string]: any;
}



interface Counter {
  (start: number): string;  // 函数
  interval: number;   // 属性
  reset(): void;   // 定好的函数:具名函数
}


function getCounter ():Counter{
  // <Counter>把右边的函数类型转化为Counter
  let c = <Counter>function (start:number){} 

  c.interval  = 2332
  c.reset = function () {}

  return c

}


class Control {
  private state: any;
}


interface SelectableControl extends Control {
  select(): void;
}


interface AAA {
  select(): void;
}

class name  implements AAA{
  constructor() {
    
  }
  select(){

  }
}


interface InameEx extends name  {

}




interface IDataBaseFormB {
  aa:string
  b:string
  // 第一种：属性类型和值约束
  [index:string]: string | number
}

let idatabaseObj:IDataBaseFormB = {
  aa:'a',
  b:'b',
}


console.log(Object.entries(idatabaseObj));

// 第二种： Object.entries(idatabaseObj)
for (const [key,val] of Object.entries(idatabaseObj)) {
    // const element = object[key];
    
    console.log(`key:${key}-value:${val}`);
    // 第三种：自己类型断言
    console.log(idatabaseObj[key as keyof IDataBaseFormB]);
    console.log(idatabaseObj[key]);
    
    
}

// for (const key in idatabaseObj) {

//     const element = idatabaseObj[key as keyof IDataBaseFormB];

// }
